#include "thread-pool.h"

void *workFunction(void *args) {
    printf("Thread PID %p Execute Task %d!\n", pthread_self(), *(int *) args);

    struct timespec sleep_time = {0, 1000 * 1000 * 100};
    nanosleep(&sleep_time, NULL);

    return NULL;
}

void test01() {
    ThreadPool *pool = createThreadPool(120, 5, 12, createTaskQueue(20), createThreadFactory(), Second, DISCARD);

    for (int i = 0; i < 100; i++) {
        int *value = (int *) malloc(sizeof(int));
        *value = i;

        submitTask(pool, workFunction, value);

        struct timespec sleep_time = {0, 1000 * 1000 * 100};
        nanosleep(&sleep_time, NULL);
    }

    struct timespec sleep_time = {3, 0};
    nanosleep(&sleep_time, NULL);

    destroyThreadPool(pool);
}

int main() {
    test01();
    return 0;
}
